import { initGlobalState } from "qiankun"
import {  reactive } from 'vue';
import router from '../router/index'

const initialState:any = reactive({
  userinfo:{
    name:'12312',
    id:'213123'
  },
  paramsinfo:{
    url:'',
    id:''
  },
  loading: false,  //  过渡效果开关
  menuIsCollapse: false, //  菜单栏收缩
  loginState: false//登录失效开关
});

// 初始化 state
const actions:any = initGlobalState(initialState)

// 用于子应改变值，通知壳项目做
actions.onGlobalStateChange((newState:any, prev:any) => {
  // console.log('------newState-------',newState)
  if(newState.paramsinfo.url){
    router.push(`${newState.paramsinfo.url}`)
  }
});

actions.getGlobalState = (key:any) => {
  return key ? initialState[key] : initialState;
};

export default actions